package com.youxuan.ssyx;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

// 串行化
public class CompletableFutureDemo4 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        // 任务 1 返回结果 1024
        CompletableFuture<Integer> futureA = CompletableFuture.supplyAsync(() -> {
            int value = 1024;
            System.out.println("任务 1:"+value);
            return value;
        }, executorService);
        // 任务 2 获取任务 1 的返回结果
        CompletableFuture<Integer> futureB = futureA.thenApplyAsync((res) -> {
            System.out.println("任务 2:"+res);
            return res;
        }, executorService);
        // 任务三 继续执行
        CompletableFuture<Void> futureC = futureA.thenRunAsync(() -> {
            System.out.println("任务 3");
        },executorService);

    }
}
